<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<html>
<head>
    <title>确认订单 - 万万书城</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }
        .header {
            background-color: #4CAF50;
            color: white;
            padding: 15px 0;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .header-container {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }
        .logo {
            font-size: 24px;
            font-weight: bold;
        }
        .nav a {
            color: white;
            text-decoration: none;
            margin: 0 15px;
        }
        .nav a:hover {
            text-decoration: underline;
        }
        .content {
            max-width: 1200px;
            margin: 20px auto;
            padding: 0 20px;
        }
        .checkout-container {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            padding: 20px;
        }
        h2 {
            margin-top: 0;
            color: #333;
        }
        .section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
        }
        .section h3 {
            margin-top: 0;
            color: #555;
            border-bottom: 1px solid #eee;
            padding-bottom: 10px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            color: #666;
        }
        input[type="text"], input[type="tel"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .order-table {
            width: 100%;
            border-collapse: collapse;
        }
        .order-table th, .order-table td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        .order-table th {
            background-color: #f0f0f0;
        }
        .total-price {
            font-size: 20px;
            font-weight: bold;
            color: #e74c3c;
        }
        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            text-decoration: none;
        }
        .btn-primary {
            background-color: #4CAF50;
            color: white;
        }
        .btn-primary:hover {
            background-color: #45a049;
        }
        .btn-secondary {
            background-color: #f0f0f0;
            color: #333;
        }
        .btn-secondary:hover {
            background-color: #e0e0e0;
        }
        .actions {
            text-align: center;
            margin-top: 30px;
        }
        .error {
            color: red;
            text-align: center;
            margin-bottom: 15px;
        }
        .user-info {
            color: white;
        }
        .user-info a {
            color: white;
            margin-left: 10px;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-container">
            <div class="logo">万万书城</div>
            <div class="nav">
                <a href="index.jsp">首页</a>
                <a href="cart">购物车</a>
                <a href="order?action=list">我的订单</a>
                <a href="userCenter">用户中心</a>
            </div>
            <div class="user-info">
                <% if (session.getAttribute("user") != null) {
                    com.wanwanbookstore.entity.User user = (com.wanwanbookstore.entity.User) session.getAttribute("user");
                    out.println(user.getUsername() + " <a href='logout'>退出</a>");
                } else {
                    out.println("<a href='login.jsp'>登录</a> <a href='register.jsp'>注册</a>");
                }
                %>
            </div>
        </div>
    </div>

    <div class="content">
        <div class="checkout-container">
            <h2>确认订单信息</h2>
            
            <% if (request.getAttribute("error") != null) {
                out.println("<div class='error'>" + request.getAttribute("error") + "</div>");
            } %>

            <form action="checkout" method="post">
                <div class="section">
                    <h3>收货信息</h3>
                    <div class="form-group">
                        <label for="phone">联系电话 *</label>
                        <input type="tel" id="phone" name="phone" value="${user.phone}" required>
                    </div>
                    <div class="form-group">
                        <label for="address">收货地址 *</label>
                        <input type="text" id="address" name="address" value="${user.address}" required>
                    </div>
                </div>

                <div class="section">
                    <h3>商品信息</h3>
                    <table class="order-table">
                        <tr>
                            <th>商品</th>
                            <th>单价</th>
                            <th>数量</th>
                            <th>小计</th>
                        </tr>
                        <c:forEach items="${cartItems}" var="item">
                            <tr>
                                <td>${item.book.title}</td>
                                <td>¥${item.book.price}</td>
                                <td>${item.quantity}</td>
                                <td>¥${item.totalPrice}</td>
                            </tr>
                        </c:forEach>
                    </table>
                </div>

                <div class="section">
                    <h3>订单金额</h3>
                    <div style="text-align: right;">
                        <span class="total-price">总计：¥${totalPrice}</span>
                    </div>
                </div>

                <div class="actions">
                    <a href="cart" class="btn btn-secondary">返回购物车</a>
                    <button type="submit" class="btn btn-primary">提交订单</button>
                </div>
            </form>
        </div>
    </div>
</body>
</html>